<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.util.*,util.*,dal.*,model.*,bll.*"%>
<%
	CompanyModel obj;
	Object temp = request.getAttribute("company");
	if (temp != null) {
		try {
			obj = (CompanyModel) temp;
		} catch (Exception ex) {
			obj = new CompanyModel();
		}
	} else {
		obj = new CompanyModel();
	}
	int role = MiscUtil.getIntUrlParam(request, "role");
	String companyType="";
	switch(role)
	{
	case 1: companyType="CLIENT";break;
	case 2: companyType="COMPETITOR";break;
	case 3: companyType="BROKER";break;
	case 4: companyType="SUPPLIER";break;
	default: companyType="COMPANY"; break;
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Company</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(pageLoaded);

function pageLoaded()
{
	turnOnNumbericInput();
	initTooltip();	
} 
	var requiredInputs = [['short_name','short_name_required'],['full_name','full_name_required']];
	var intInputs = [];
	var doubleInputs = [];
	var dateInputs = [];
	var timeInputs = [];
	var mailInputs = [['contact_email_1','contact_email_1_invalid'],['contact_email_2','contact_email_2_invalid']];
	

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
		if (checkIntInputs(intInputs) == false) {
			valid = false;
		}
		if (checkDoubleInputs(doubleInputs) == false) {
			valid = false;
		}
		if (checkDateInputs(dateInputs) == false) {
			valid = false;
		}
		if (checkTimeInputs(timeInputs) == false) {
			valid = false;
		}
		if (checkMailInputs(mailInputs) == false) {
			valid = false;
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
	
	
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
				<form id="inputForm" action="company?mode=update&role=<%=role %>" method="post" onSubmit="return checkInputs()" >
					<table class="tblInput">
						<tr>
							<td class="inputHeader">EDIT <%=companyType%> INFO</td>
						</tr>
							<tr>
					<td style="padding-left: 200px; padding-right: 200px;">
						<table cellspacing="0px">
						<tr class="trField">
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput">
								<input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" value="<%=obj.getId()%>" title="Id of this company. Note: Can not edit"/>
								<span class="textGuide"> (Can not edit)</span>
							</td>
							<td class="tdErrMsg"></td>
							<td rowspan="12"></td>
							<td class="tdFieldName">Remark</td>
							<td class="tdFieldInput"><textarea id="remark" name="remark" rows="5" class="inputTextarea" title="Remark of new company."><%=obj.getRemarkToString() %></textarea>
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Code</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="code" name="code" maxlength="20" value="<%=obj.getCodeToString() %>" title="Code of new company." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Place</td>
						<td class="tdFieldInput">
							<select id="id_place" name="id_place" class="hyjack" title="Choose a place for this company.">
								<%=HtmlUtil.<PlaceModel>genModelSelect(CacheUtil.getPlaceList(), null,obj.getIdPlace())%>
							</select>
							<input class="btnAdd" type="button" id="addNewPlace" value="" onclick="ajaxAddItem('#id_place', 'place', 'name', 'Please enter new place name!');" title="Click here to add new place."/>
						</td>
						<td class="tdErrMsg">
						</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Short Name</td>
							<td class="tdFieldInput"><input class="inputText" type="text" id="short_name" name="short_name" maxlength="25" value="<%=obj.getShortNameToString()%>" title="Change short name of this company. Note: Required"  onblur="validateRequiredInput('short_name');"/></td>
							<td class="tdErrMsg">
								<span id="short_name_required" class="errMsg" style="display: none;" title="Short name is required">(!)</span> 
								
								<span id="short_name_error" class="errMsg" title="<%=obj.errMsgs.ShortName%>"></span>
							</td>
							<td class="tdFieldName">Contact Person 1</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_person_1" name="contact_person_1" maxlength="255" value="<%=obj.getContactPerson1ToString() %>" title="Name of contact person 1." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Full Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="full_name" name="full_name" maxlength="255" value="<%=obj.getFullNameToString() %>" title="Change full name of this company." />
							</td>
							<td class="tdErrMsg">
								<span id="full_name_required" class="errMsg" style="display: none;" title="Full name is required">(!)</span> 
								
								<span id="full_name_error" class="errMsg" title="<%=obj.errMsgs.FullName%>"></span>
							</td>
							<td class="tdFieldName">Telephone</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_phone_1" name="contact_phone_1" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getContactPhone1ToString() %>" title="Phone number of contact person 1 . Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Foreign Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="foreign_name" name="foreign_name" maxlength="255" value="<%=obj.getForeignNameToString() %>" title="Change foreign name of this company." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Mobile</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_mobile_1" name="contact_mobile_1" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getContactMobile1ToString() %>" title="Mobile number of contact person 1 . Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput">
								<textarea id="description" name="description" rows="5" class="inputTextarea" title="Edit description for this company."><%=obj.getDescriptionToString() %></textarea>
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Email</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_email_1" name="contact_email_1" maxlength="255" value="<%=obj.getContactEmail1ToString() %>" title="Email of contact person 1." onchange="validateMailInput('contact_email_1')" />
							</td>
							<td class="tdErrMsg">
								<span id="contact_email_1_invalid" class="errMsg" style="display: none;" title="The email you input is invalid">(!)</span> 
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Address</td>
							<td class="tdFieldInput">
								<textarea id="address" name="address" rows="5" class="inputTextarea" title="Change address of this company."><%=obj.getAddressToString() %></textarea>
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Contact Person 2</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_person_2" name="contact_person_2" maxlength="255" value="<%=obj.getContactPerson2ToString() %>" title="Name of contact person 2." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Telephone</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="telephone" name="telephone" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getTelephoneToString() %>" title="Change phone number of this company. Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Telephone</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_phone_2" name="contact_phone_2" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getContactPhone2ToString() %>" title="Phone number of contact person 2 . Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Tax Code</td>
							<td class="tdFieldInput">
								<input class="inputInt" type="text" id="tax_code" name="tax_code" maxlength="10" value="<%=obj.getTaxCodeToString() %>" title="Change tax code of this company. Note: Integer only." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Mobile</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_mobile_2" name="contact_mobile_2" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getContactMobile2ToString() %>" title="Mobile number of contact person 2 . Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Fax</td>
							<td class="tdFieldInput">
								<input class="inputInt" type="text" id="fax" name="fax" maxlength="10" value="<%=obj.getFaxToString()%>" title="Fax number of new company. Note: Integer only." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Email</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="contact_email_2" name="contact_email_2" maxlength="255" value="<%=obj.getContactEmail2ToString() %>" title="Email of contact person 2." onchange="validateMailInput('contact_email_2')" />
							</td>
							<td class="tdErrMsg">
								<span id="contact_email_2_invalid" class="errMsg" style="display: none;" title="The email you input is invalid">(!)</span> 
							</td>
						</tr>
						<tr>
							<td class="tdFieldName">Is Competitor</td>
							<td class="tdFieldInput">
							<%if(role!=2) {%>
								<input class="inputCheckbox" title="Check this option to mark this company is a competitor." type="checkbox" id="is_competitor" name="is_competitor" <%=obj.getIsCompetitor() == true ? "checked" : ""%> />
							<%} else { %>
								<input class="inputCheckbox" checked="checked" disabled="disabled" title="This company is a competitor.Note: Cannot edit." type="checkbox" />
							<%}%>
							</td>
							<td class="tdErrMsg"></td>
							
							<td class="tdFieldName">Is Supplier</td>
							<td class="tdFieldInput">
							<%if(role!=4) {%>
								<input class="inputCheckbox" title="Check this option to mark this company is a supplier." type="checkbox" id="is_provider" name="is_provider" <%=obj.getIsProvider() == true ? "checked" : ""%> />
							<%} else { %>
								<input class="inputCheckbox" checked="checked" disabled="disabled" title="This company is a supplier.Note: Cannot edit." type="checkbox" />
							<%}%>
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr>
							<td class="tdFieldName">Is Client</td>
							<td class="tdFieldInput">
							<%if(role!=1) {%>
								<input class="inputCheckbox" title="Check this option to mark this company is a client." type="checkbox" id="is_client" name="is_client" <%=obj.getIsClient() == true ? "checked" : ""%> />
							<%} else { %>
								<input class="inputCheckbox" checked="checked" disabled="disabled" title="This company is a client.Note: Cannot edit." type="checkbox" />
							<%}%>
							</td>
							<td class="tdErrMsg"></td>
							
							<td class="tdFieldName">Is Broker</td>
							<td class="tdFieldInput">
							<%if(role!=3) {%>
								<input class="inputCheckbox" title="Check this option to mark this company is a broker." type="checkbox" id="is_broker" name="is_broker" <%=obj.getIsBroker() == true ? "checked" : ""%> />
							<%} else { %>
								<input class="inputCheckbox" checked="checked" disabled="disabled" title="This company is a broker.Note: Cannot edit." type="checkbox" />
							<%}%>
							</td>
							<td class="tdErrMsg"></td>
						</tr>

						<tr class="trInputBottom">
<!-- 							<td class="tdFieldName"></td> -->
							<td colspan="7" class="tdSubmit" style="text-align: center;"><input class="btnSubmit" type="submit" value="Submit" title="Click to save above information."/></td>

						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<%
	
		String urlCompanyList = "companyList.jsp?embedded=true&role="+role;
	%>
		<jsp:include page='<%=urlCompanyList%>'></jsp:include>
	</div>
</body>
</html>